package com.course.server.common;

import lombok.Data;

/**
 * @author yangw
 * @created 2021/3/18
 * @description
 */
@Data
public class Result {
    private boolean success;
    private int code;
    private String msg;
    private Object data;

    public static Result success(Object data) {
        Result result = new Result();
        result.setCode(ResultEnum.SUCCESS.getCode());
        result.setMsg(ResultEnum.SUCCESS.getMsg());
        result.setData(data);
        result.setSuccess(true);
        return result;
    }

    public static Result failure(int code, String message) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(message);
        result.setSuccess(false);
        return result;
    }

    public static Result success() {
        Result result = new Result();
        result.setCode(200);
        result.setMsg("操作成功");
        result.setSuccess(true);
        return result;
    }

    public static Result failure() {
        Result result = new Result();
        result.setCode(ResultEnum.ERROR.getCode());
        result.setMsg(ResultEnum.ERROR.getMsg());
        result.setSuccess(false);
        return result;
    }

    public static Result success(ResultEnum resultEnum, Object data) {
        Result result = new Result();
        result.setCode(resultEnum.getCode());
        result.setMsg(resultEnum.getMsg());
        result.setData(data);
        result.setSuccess(true);
        return result;
    }

    public static Result failure(ResultEnum resultEnum) {
        Result result = new Result();
        result.setCode(resultEnum.getCode());
        result.setMsg(resultEnum.getMsg());
        result.setSuccess(false);
        return result;
    }


}
